package com.zzk.lanouhn.myapplication1.view;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.zzk.lanouhn.myapplication1.R;

/**
 * Created by lanouhn on 16/9/13.
 */
public class MineFragmentTouXiangPop extends PopupWindow {
    private TextView btn_take_pop, btn_pick_photo, btn_cancel;
    private View mMenuView;

    public MineFragmentTouXiangPop(Activity content, View.OnClickListener itemsOnclick) {
        super(content);
        LayoutInflater inflater = (LayoutInflater) content.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mMenuView = inflater.inflate(R.layout.pop_mine_touxiang, null);

        btn_take_pop = (TextView) mMenuView.findViewById(R.id.mine_btn_take_photo);
        btn_pick_photo = (TextView) mMenuView.findViewById(R.id.mine_btn_pick_photo);
        btn_cancel = (TextView) mMenuView.findViewById(R.id.mine_btn_cancel);

        btn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        btn_take_pop.setOnClickListener(itemsOnclick);
        btn_pick_photo.setOnClickListener(itemsOnclick);

        // 设置SelectPicPopupWindow的View
        this.setContentView(mMenuView);
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(ActionBar.LayoutParams.MATCH_PARENT);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(ActionBar.LayoutParams.WRAP_CONTENT);

        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);

        // 设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.AppTheme);

        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        // 设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);

        mMenuView.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                int height = mMenuView.findViewById(R.id.mine_pop_layout).getTop();
                int y = (int) event.getY();
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (y < height) {
                        dismiss();
                    }
                }
                return false;
            }
        });

    }

}
